// packageG/storeCategoryList/storeCategoryList.js
var g = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    active2: !0,
    categoryList: [],//左侧分类
    page: 1,
    flxShow: !1,
    recommend: [],
    // activeName: "",
    secondaryId: "",
    foodInfo: [],
    language: "",
    activeNames: ['1'],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCategory(); //获取分类列表
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    var t = wx.getStorageSync("langIndex");
    console.log(t,'tttttttttttt')
    this.setData({
        language: t.en
    })
    var a = wx.getStorageSync("integral");
    a && this.setData({
        integral: a
    });
  },

  containsHttp(str) {  
    // return /http(s)?:\/\//.test(str);  
    return str.includes('https://shops.cg500.com')
},


  gotosearch: function() {
    wx.navigateTo({
      url: '/packageC/o2o/o2oSearch/o2oSearch?city=1&point={}',
    })
},
  onChange: function(t) {
    this.setData({
        activeName: t.detail
    });
},
  getCategory: function () {
    var t = this;
    g._getNetWork({
      url: g.getNetAddresss("HuanNiu.get_store_cate"),
      success: function (res) {
        console.log(res, 'getCategory')
        var e = res.data,
          s = e.result,
          o = e.msg,
          i = e.data;
        if (0 == s) return g.tips(o);
        t.setData({
          categoryList: i,
          recommend: i[0].child,
          secondaryId: i[0].child[0].id
        });
        console.log(t.data.categoryList, 'categoryList')
      }
    });
  },
  allList: function () {
    this.setData({
      active2: !0,
      active: 9999
    })
    // this.getCategoryNew("allList");
  },
  chooseSecondary: function(t) {
    var a = t.target.dataset.item || t.currentTarget.dataset.item;
    console.log(a,'aaaaaaa')
    this.setData({
      secondaryId: a.id
    })
    this.getData(a.id)
},
getGoodsData:function(id){

},
onPageScroll: function(t) {
  console.log(t,'kkkkkkkk')
  
},
changeScroll: function(t) {
  
},
bindscrolltolower: function(t) {
  this.data.isLoadMore ? this.getMoreData() : (console.log("没有更多数据"), wx.showToast({
      title: "没有更多数据",
      icon: "none"
  }));
},
upper: function(t) {
  this.setData({
      flxShow: !1
  });
},
onChange(event) {
  this.setData({
    activeNames: event.detail,
  });
},
onOpen(event) {
  // Toast(`展开: ${event.detail}`);
},
onClose(event) {
  // Toast(`关闭: ${event.detail}`);
},

immidateleyBuy:function(e){
  console.log(e.currentTarget.dataset.good.id,'gotoGoods')
  let id = e.currentTarget.dataset.good.id
  wx.navigateTo({
    url: "/packageA/detail_v2/detail_v2?id=" + id
})
},
getMoreData: function() {
  console.log('触底了')
  var t = this;
  if (t.data.page >= t.data.total_page) return t.setData({
      LoadMoreTest: "没有更多"
  }), void t.setData({
      isLoadMore: !1
  });
  t.setData({
      isLoadMore: !0
  });
  var e = t.data.page;
  if (e += 1, t.setData({
      page: e
  }), "tiktok" != this.data.current_goods_key) {
      var s, o = g.getNetAddresss("HuanNiu.get_store_list");
      g._getNetWork({
          url: o,
          data: {
            cate_id: this.data.secondaryId,
            page: this.data.page
          },
          success: function(a) {
              var e = a.data;
              if (t.setData({
                  isLoadMore: !0
              }), 1 != e.result) {
                  var s = t.data.page;
                  return s -= 1, void t.setData({
                      page: s,
                      isLoadMore: !1
                  });
              }
              var o = t.data.foodInfo;
              var foodArr1 = e.data.data.map(item => {
                return {
                  ...item,
                  isPic: t.containsHttp(item.thumb) ? true : false,
                  newPic: t.containsHttp(item.thumb) ? item.thumb : 'https://shops.cg500.com/static/upload/'+item.thumb,
                }
              });
              console.log(foodArr1,'foodArr1');
              // o = o.concat(e.data.data), t.setData({
              //     foodInfo: o
              // });
              o = o.concat(foodArr1), t.setData({
                foodInfo: o
            });
          },
          fail: function(t) {
              console.log(t);
          }
      });
  } else this.getTikTokGoods();
},
getData: function(t) {
  var e, s = this;
  var i = g.getNetAddresss("HuanNiu.get_store_list");
  g._getNetWork({
      url: i,
      data: {
        cate_id: t,
        page: this.data.page
      },
      success: function(t) {
          var a = t.data;
          console.log(a.data.data,'get_store_list')
          // 1 == a.result ? (s.setData({
          //     page: 1,
          //     isLoadMore: !0,
          //     total_page: a.data.last_page,
          //     foodInfo: a.data.data
          // }), 1 == a.data.last_page ? s.setData({
          //     LoadMoreTest: "没有更多"
          // }) : s.setData({
          //     LoadMoreTest: "加载更多"
          // }), s.data.total_page || s.setData({
          //     total_page: 0
          // })) : (wx.showToast({
          //     title: a.msg,
          //     icon: "none"
          // }), console.log(a.msg));
          1 == a.result ? (console.log(a.data.data,'foodInfo'),
          foodArr = a.data.data.map(item => {
            return {
              ...item,
              isPic: s.containsHttp(item.thumb) ? true : false,
              newPic: s.containsHttp(item.thumb) ? item.thumb : 'https://shops.cg500.com/static/upload/'+item.thumb,
            }
          }),console.log(foodArr,'foodArr'),
          
          s.setData({
            page: 1,
            isLoadMore: !0,
            total_page: a.data.last_page,
            foodInfo: foodArr
        }), 1 == a.data.last_page ? s.setData({
            LoadMoreTest: "没有更多"
        }) : s.setData({
            LoadMoreTest: "加载更多"
        }), s.data.total_page || s.setData({
            total_page: 0
        })) : (wx.showToast({
            title: a.msg,
            icon: "none"
        }), console.log(a.msg));
        
      }
  });
},
  tabsa: function (t) {
    var a = t.currentTarget.dataset.index,
      e = t.currentTarget.dataset.item;
    console.log(a, t, '左侧切换')
      this.tabsaData(a, e)
      this.setData({
        active2: !1,
        active: a,
        page: 1,
        secondaryId: e.child ? e.child[0].id : 999
      });
      // this.getData(e.child[0].id)
      this.getData(this.data.secondaryId)
  },
  tabsaData: function(t, a) {
    console.log(t, a, "sssssss")
    this.setData({
      // recommend: a.child
      recommend: a.child ?  a.child : []
    });
},
  getMoreCategoryNew: function() {
    // var t = this, e = this.data;
    // if (!(e.main_category_page >= e.main_category_total)) {
    //     console.log("加载更多主分类"), this.data.main_category_page++;
    //     var s = g.getNetAddresss(a.home), o = wx.getStorageSync("yz_basic_info"), i = "";
    //     1 == o.home.item.is_decorate && "category04" == o.home.item.ViewSet.category.name && "tiktok" == this.data.current_goods_key && (s = g.getNetAddresss("plugin.tiktok-cps.api.goods.good-cate"), 
    //     i = "04");
    //     var r = {
    //         page: this.data.main_category_page
    //     };
    //     g._getNetWork({
    //         url: s,
    //         data: r,
    //         success: function(a) {
    //             var e = a.data, s = [];
    //             s = "04" == i ? e.data.data : e.data.category.data, t.setData({
    //                 onelist: t.data.onelist.concat(s)
    //             });
    //         }
    //     });
    // }
},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // console.log(this.containsHttp('https://shops.cg500.com/static/upload/images/45/2024/01/9e25f8fb702e07ebef916991118df2d4.jpg'),'hahahaahh')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})